package cn.kgc.utils;

import java.io.Serializable;

public class PageInfo<T> implements Serializable {
    private Integer currentPageNo = 1;

    private Integer pageSize = 5;

    private Integer totalConut;

    private Integer totalPage;

    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public PageInfo() {
    }

    public PageInfo(Integer currentPageNo, Integer pageSize, Integer totalConut, Integer totalPage) {
        this.currentPageNo = currentPageNo;
        this.pageSize = pageSize;
        this.totalConut = totalConut;
        this.totalPage = totalPage;
    }

    public Integer getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(Integer currentPageNo) {
        this.currentPageNo = currentPageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if (pageSize<1){
            this.pageSize = 5;
        }else {
            this.pageSize = pageSize;
        }

    }

    public Integer getTotalConut() {
        return totalConut;
    }

    public void setTotalConut(Integer totalConut) {

        this.totalConut = totalConut;
        int pageConut = this.calcPage();
        this.setTotalPage(pageConut);
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public int calcPage(){
        int pageConut = this.totalConut%this.pageSize == 0? this.totalConut/this.pageSize:this.totalConut/this.pageSize+1;
        return pageConut;
    }
}
